package com.galaxy.controller;

import com.galaxy.service.FileUpdateService;
import com.galaxy.util.M;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 通用文件上传接口
 * @author anjie
 * @email anjie@032t.com
 * @date 2020年8月10日
 */
@RestController
@RequestMapping("/galaxy")
public class FileUploadController {

    @Autowired
    MinioClient minioClient;

    @Autowired
    FileUpdateService fileUpdateService;

    /**
     * 上传文件到 minio
     * @param uploadFile 需要传入的文件
     * @return json
     * @throws Exception
     */
    @RequestMapping("/upload/{bn}")
    public Object upload(@RequestParam("file") MultipartFile uploadFile,
                         @PathVariable("bn") String bn,String path) throws Exception {

        System.out.println("--------------------文件上传开始------------------------");
        System.out.println("文件对象:" + uploadFile);
        System.out.println("存储桶名称:" + bn);
        System.out.println("path:" + path);
        M m = fileUpdateService.putFile(uploadFile, bn, path, null);
        System.out.println("--------------------文件上传完毕------------------------");
        return m;


    }


}
